/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.Desktop.Plugin.FileUploader;

import com.kylingroup.Desktop.PlugLoader.KGDesktopPlugloader;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import javafx.scene.layout.BorderPane;

/**
 *
 * @author kylin
 */
public class KGPlugFileuploader implements KGDesktopPlugloader{
    private Tab tab=null;
    private BorderPane pane=null;
    
    public KGPlugFileuploader(){
        //System.out.println("[Plugin-FileUploader]:[create]");
    }
    
    @Override
    public Node install(){
        return load();
    }
    
    public Node load(){
        FXMLLoader loader=new FXMLLoader();
        InputStream in=KGPlugFileuploader.class.getResourceAsStream("Fileuploader.fxml");
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        loader.setLocation(KGPlugFileuploader.class.getResource("Fileuploader.fxml"));
        System.out.println("[Plugin-FileUploader]:[loader}-->"+loader.toString());
        FileuploaderController controller=new FileuploaderController();
        loader.setController(controller);
        Platform.runLater(new Runnable(){
            @Override
            public void run() {
                try{
                    pane=(BorderPane)loader.load(in);

                    System.out.println("[Plugin-FileUploader]:[pane}-->"+pane.toString());
                    //FileuploaderController controller=new FileuploaderController();
                    //
                }catch (IOException ex) {
                }finally{
                    try{
                        in.close();
                    }catch(IOException ex){}
                }
            }
        });
        //System.out.println("[Plugin-FileUploader]:[controller}-->"+controller.toString());
        
        return pane;
    }
    
    public String getFXMLURL(){
        System.out.println("file:"+KGPlugFileuploader.class.getResource("Fileuploader.fxml").getFile());
        try {
            System.out.println("url:"+KGPlugFileuploader.class.getResource("Fileuploader.fxml").toURI().toURL());
        } catch (URISyntaxException ex) {
            Logger.getLogger(KGPlugFileuploader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MalformedURLException ex) {
            Logger.getLogger(KGPlugFileuploader.class.getName()).log(Level.SEVERE, null, ex);
        }
        return  KGPlugFileuploader.class.getResource("Fileuploader.fxml").getFile();

    }
    
    @Override
    public boolean uninstall() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean extract() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    @Override
    public void restart() {
        try {
            Runtime.getRuntime().exec("KGDesktop.sh");
        } catch (IOException ex) {
            Logger.getLogger(KGPlugFileuploader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
